<?php

/**
 * Created by PhpStorm.
 * User: evan
 * Date: 16/8/31
 * Time: 下午11:03
 */
class Base extends MY_Admin_Controller
{
    public function index()
    {
        $this->load->view('admin/base/index');
    }
    
    public function image_upload()
    {    
    	$fid = !empty($_FILES['imgFile']['tmp_name'])?$this->uploadFile('imgFile'):'';
    	
    	$file_url = full_id_url($fid);
    	
    	echo json_encode(array('error' => 0, 'url' => $file_url));
    }
    
    public function msg()
    {
    	$this->load->model('staff/Model_staff_work','staff_work');
    	$staff_work = $this->staff_work->getOne(array('sid'=>$this->uInfo['sid'], 'end_time >'=>date('Y-m-d H:i:s', strtotime("-5 minutes"))));
    	
    	if($staff_work)
    	{
    		$data = array(
    				'end_time'=>date('Y-m-d H:i:s'), 
    				'work_time'=>floor((strtotime($staff_work['end_time'])-strtotime($staff_work['start_time']))/60),
    				);
    		$this->staff_work->save($data, $staff_work['id']);
    	}else{
    		$data = array(
    				'sid'=>$this->uInfo['sid'],
    				'realname'=>$this->uInfo['realname'],
    				'start_time'=>date('Y-m-d H:i:s'),
    				'start_date'=>date('Y-m-d'),
    				'end_time'=>date('Y-m-d H:i:s'),
    				'work_time'=>0,
    		);
    		$this->staff_work->save($data);
    	}
    	
    	$data = array();
    	
    	$this->load->model('common/Model_audit_content', 'ac');
    	$data['content_audit_total'] = $this->ac->count(array('status'=>AUDIT_STATUS_NOT));
    	
    	$this->load->model('user/Model_user_realname_auth','ura');
    	$data['realname_auth_total'] = $this->ura->count(array('status'=>USER_REALNAME_AUTH_STATUS_NOT));
    	
    	echo json_encode(array('code' => 200, 'data' => $data));
    }


    /**
     * 主页
     */
    public function dashboard()
    {
        $this->load->model('common/Model_file','file');
        $fileInfo = $this->file->getAllLists();


        //最新用户
        $this->load->model('user/model_user','user');
        $userInfo = $this->user->lists(0,5);
        $total_user = $this->user->count(array('status' => USER_STATUS_NORMAL));


        //支付用户
        $this->load->model('finance/model_finance_payment','finance');
        $financeInfo = $this->finance->lists(0, 5, array('is_paid' => FINANCE_PAYMENT_IS_PAID_NEED));
        $total_pay_amount = $this->finance->count(array('is_paid' => FINANCE_PAYMENT_IS_PAID_NEED));


        //直播排行
        $this->load->model('direct_seeding/Model_direct_seeding', 'ds');
        $directInfo = $this->ds->lists(0,5,array(),true,'join_num desc');
        $total_ds = $this->ds->count();


        //竞拍排行
        $this->load->model('auction/Model_auction', 'auction');
        $auctionInfo = $this->auction->lists(0, 5, array('win_amount!=' => 0),true,'aid desc');
        $total_auction = $this->auction->count();


        $data = array
        (
            'userInfo'    => $userInfo,
            'total_user'  => $total_user,
            'fileInfo'    => $fileInfo,
            'financeInfo' => $financeInfo,
            'directInfo'  => $directInfo,
            'auctionInfo' => $auctionInfo,
            'total_ds'    => $total_ds,
            'total_auction'    => $total_auction,
            'total_pay_amount' => $total_pay_amount,
        );

        $this->load->view('admin/base/dashboard',$data);
    }
}